package com.school.sports.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.school.sports.entity.Schedule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 赛程数据访问层
 */
@Mapper
public interface ScheduleMapper extends BaseMapper<Schedule> {

    /**
     * 根据ID查询赛程详情（包含项目、场地、裁判信息）
     * @param id 赛程ID
     * @return 赛程详情
     */
    @Select("SELECT s.*, " +
            "p.name as project_name, p.type as project_type, p.gender_limit as project_gender_limit, " +
            "v.name as venue_name, v.location as venue_location, v.capacity as venue_capacity, " +
            "u.real_name as referee_name, u.phone as referee_phone " +
            "FROM schedule s " +
            "LEFT JOIN project p ON s.project_id = p.id " +
            "LEFT JOIN venue v ON s.venue_id = v.id " +
            "LEFT JOIN user u ON s.referee_id = u.id " +
            "WHERE s.id = #{id}")
    Schedule selectScheduleWithDetails(Long id);
}